namespace AutoTest.Core.Messaging
{
    using Microsoft.Practices.ServiceLocation;
    using Ninject.Core.Infrastructure;

    public class MessageBus : IMessageBus
    {
        readonly IServiceLocator _serviceLocator;

        public MessageBus(IServiceLocator serviceLocator)
        {
            _serviceLocator = serviceLocator;
        }


        public void Publish<T>(T message)
        {
            Ensure.ArgumentNotNull(message, "message");
            //ignore the sender for now...?
            var instances = _serviceLocator
                .GetAllInstances<IConsumerOf<T>>();
            instances
                .Each(c => c.Consume(message));
        }
    }
}